package com.wise.site.push;


import org.json.JSONObject;

import com.wise.site.protocol.base.ProtocolManager;
import com.wise.site.protocol.base.SoapAction;
import com.wise.site.protocol.base.SoapAction.ACTION_TYPE;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.provider.Settings.Secure;
import android.util.Log;

public class BootBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context cxt, Intent intent) {
		String action = intent.getAction();
		Log.w(PushService.class.getName(), "onStart");
		if("android.alarm.wise.action".equals(action)){
			downloadData(cxt);
		} else if(Intent.ACTION_BOOT_COMPLETED.equals(action)){
			cxt.startService(new Intent(cxt, PushService.class));
		}
	}

	private void downloadData(Context cxt) {
		String android_id=Secure.getString(cxt.getContentResolver(), Secure.ANDROID_ID);
		
		SoapAction<Integer> sAction = new SoapAction<Integer>(ACTION_TYPE.ACTION_COMMON, "devicebook"){
			@Override
			protected Integer parseJson(String response) throws Exception {
				JSONObject json = new JSONObject(response);
				System.out.println(json);
				return 1;
			}
		};
		sAction.addJsonParam("UUID", android_id);
		sAction.addJsonParam("PhoneType", 1);
		sAction.addJsonParam("IP", "");
		
		ProtocolManager.getProtocolManager().submitAction(sAction);
	}

}
